# While实现左下三角行
i=1
while i <10:
   j=1
   while j<=i:
       print('{}*{} = {:=2}'.format(i,j,i*j), end="    ")
       j+=1
   print()
   i+=1

# While实现左上三角行
i=1
while i <10:
   j=1
   while j<=10-i:
       print('{}*{} = {:=2}'.format(i,j,i*j), end="    ")
       j+=1
   print()
   i+=1


# While实现右上三角行
i=1
while i <10:
   j=1
   while j<i:
       print(end="            ")
       j+=1
   k=1
   while k<=10-i:
       print('{}*{} = {:=2}'.format(i,k,i*k), end="    ")
       k+=1
   print()
   i+=1

# While实现右下三角行
i=1
while i <10:
    j=1
    while j<10-i:
        print(end="            ")
        j+=1
    k=1
    while k<=i:
        print('{}*{} = {:=2}'.format(i,k,i*k), end="    ")
        k+=1
    print()
    i+=1


# for in 实现左下三角行
for i in range(1,10):
   for j in range(1,i+1):
       print('{}*{} = {:=2}'.format(i,j,i*j), end="  ")
   print()

# for in 实现 左上三角行
for i in range(1,10):
   for j in range(i,10):
       print('{}*{} = {:=2}'.format(i,j,i*j), end="   ")
   print(" ")

#for in 实现 右上三角行
for i in range(1,10):
   for j in range(1,i):
       print(end="          ")
   for k in range(i,10):
       print('{}*{} = {:=2}'.format(i,k,i*k), end="  ")
   print(" ")

# for in 实现 右下三角行
for i in range(1,10):
   for j in range(1,10-i):
       print(end="          ")
   for k in range(1,i+1):
       print('{}*{} = {:=2}'.format(i,k,i*k), end="  ")
   print(" ")


#2, 定义一个统计目录大小的函数
import os
all_size = 0
def dir_size(dir_name):
    global all_size
    file_list = os.listdir(dir_name)   # 获取目录内的文件列表
    for file in file_list:
        file_path = os.path.join(dir_name,file)
        print(dir_name)
        if os.path.isfile(file_path):  # 如果时文件
            size = os.path.getsize(file_path)
            print(size)
            all_size += size  # all_size = all_size + size
            print(file_path)
        else:
            dir_size(file_path)  # 递归调用


print('-' * 50)
print('目标文件如下')
print('-' * 50)
dir_size("C:/Users/louis.shi/Desktop/BPCS/")
print('-' * 50)
print('目录总大小:', all_size, '字节')
print('-' * 50)

# 3 自动取款机模拟系统
'''
  取款机系统数据源
  查看信息，添加信息
  存钱
  取钱
  修改密码
  界面和交互
'''
import getpass
#创建一个list变量 User_Information  存储用户信息
User_Information =[
      {"User_Name": "ZhangSan", "Password" : "111111", "balance" : 123456, "Acoount_State" : True, "Error_Count": 0},
      {"User_Name": "LiSi", "Password" : "222222", "balance" : 453636, "Acoount_State" : True, "Error_Count": 0},
      {"User_Name": "WanfWu", "Password" : "333333", "balance" : 98766.7, "Acoount_State" : False, "Error_Count": 3},
      {"User_Name": "ZhaoLiu", "Password": "444444", "balance": 7654678.7, "Acoount_State": False, "Error_Count": 3}]
User_Information1 = [{'ZhangSan':{"User_Name":"ZhangSan"},"Password":11111, "balance":123456,"Acoount_State" : True, "Error_Count": 0 }]
# 密码错误次数
Error_Count = 0
#登陆函数
def Account_Verification(sName,sPassword):
    # 账号认证 账号密码
    global User_Information
    for User_Id in range(len(User_Information)):
        if sName == User_Information [User_Id] ["User_Name"]: # 查询用户是否存在
            if sPassword == User_Information [User_Id] ["Password"]:
                if User_Information[User_Id]["Account_State"] == True:
                    print("欢迎使用")
                else:
                    print("账号已锁定")
            else:
                User_Information[User_Id]["Error_Count"] +=1
                print ("密码错误，错误3次将被锁定，您还有{}次机会".format(3 - User_Information[User_Id]["Error_Count"]))
        else:
            print("账号不存在")
# 余额查询函数
def Account_Balance(User_Id):
    global User_Information
    print("您的余额为{}元".format(User_Information[User_Id]["Balance"]))
# 存款函数
def Deposit_Money(User_Id):
    global User_Information
    while True:
        money = input ("请输入存款金额")
        if float(money) <= 0:
            print("输入金额需大于0")
        else:
            User_Information[User_Id]["balance"] += int(money)
            break
# 取款函数
def Withdraw_Money(User_Id):
    global User_Information
    while True:
        money = input ("请输入取款金额")
        if float(money) <= 0:
            print("输入金额需大于0")
        elif float(money) > User_Information[User_Id]["banlance"]:
            print("金额不足")
        else:
            User_Information[User_Id]["balance"] -= int(money)
            break
#修改密码
def Change_Password(User_ID):
    global User_Information
    global Error_Count
    while True:
        if User_Information[User_ID]["Error_Count"] == 3:
            User_Information[User_ID]["Account_State"] = False
            print("账号已经锁定")
            break
        for n in range(3):
            sPassword1 = input ("请输入")
            sPassword2 = input("请再次输入")
            if sPassword1 != sPassword2:
                print("密码不一致")
                continue
            User_Information[User_ID]["Password"] = str(sPassword2)
            break
        break
#登陆界面
while True:
    print("=" * 30, "自动取款机", "=" * 30)
    sUser_Name = input ("请输入用户名")
    sPass_Word = getpass.getpass ("请输入密码")
    User_Id = Account_Verification(sUser_Name,sPass_Word)
    if User_Id < 0:
        continue
    while True:
        if User_Information[User_Id]["Account_State"] == False:
            print("已锁定")
            break
        print ("=" * 22, "请选择业务", "=" * 22)
        print("{0:1}{1；13}{2：15}".format(" ", "1. 余额查询", "2.存款"))
        print("{0:1}{1；13}{2：15}".format(" ", "3. 取款", "4.修改密码"))
        print("{0:1}{1；13}".format(" ", "5. 退出"))
        print("=" * 50)
        if key == "1":
            print ("=" * 23, "余额查询", "=" * 23)
            Account_Balance(User_Id)
            Input("按回车继续")
        elif key == "2":
            print("=" * 25, "余额查询", "=" * 25)
            Withdraw_Money(User_Id)
            Input("按回车继续")





